package light.head.controller.oa;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import light.head.constant.Parm;
import light.head.constant.Sys;
import light.head.constant.Url;
import light.head.dao.oa.AuditStatusDAO;
import light.head.dao.oa.LeaveDAO;
import light.head.dao.sys.OrganDAO;
import light.head.enm.RESULT;
import light.head.framework.base.SupporterController;
import light.head.framework.entity.PageBean;
import light.head.model.LeaveManage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping(value = Url.LEAVERECORD)
public class LeaveRecordController extends SupporterController{
	
	
	private LeaveDAO leaveDAO;
	private OrganDAO organDAO;
	private AuditStatusDAO auDAO;
	@RequestMapping(value = Url.INIT)
	public ModelAndView init(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView(Url.LEAVERECORD_INIT);
	}

	
	@RequestMapping(value = Url.QUERY)
	public ModelAndView query(HttpServletRequest request, HttpServletResponse response) throws Exception {
		PageBean pb = createPageBean(request);
		Map<String, String> map = createQueryMapByParmName(request, Parm.OC, Parm.REASON, Parm.ST, Parm.END, Parm.UN, Parm.DELETED);
		//map.put(Parm.OC, cu_organCode(request).toString());
		Integer oc = organDAO.getRoot(cu_organCode(request)).getCode();
		if (leaveDAO.findByMap_2(organDAO.getSonCodeList(oc),map, pb) == RESULT.SUCCESS) {
			LeaveManage re = null;
			for (Object o : pb.getResultList()) {
				re = (LeaveManage) o;
				if (re.getHead() == false){
					re.setAuditStatusList(auDAO.findByBusinessMc(Sys.B_TWO, re.getCode()));
				}else{
					re.setAuditStatusList(auDAO.findByBusinessMc(Sys.B_SIX, re.getCode()));
				}
				
			}
		}
		request.setAttribute(Parm.PAGE_BEAN, pb);
		return new ModelAndView(Url.LEAVERECORD_LIST);
	}
	
	
	@Autowired
	public void setLeaveDAO(LeaveDAO leaveDAO) {
		this.leaveDAO = leaveDAO;
	}
	@Autowired
	public void setOrganDAO(OrganDAO organDAO) {
		this.organDAO = organDAO;
	}
	@Autowired
	public void setAuDAO(AuditStatusDAO auDAO) {
		this.auDAO = auDAO;
	}
}
